package com.zjy.web.exception;

import com.zjy.web.domain.model.IResultCode;
import com.zjy.web.domain.model.Result;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serial;

/**
 * @author zhangjianyu
 * email: 578547270@qq.com
 * create_time: 2024-10-18 14:32
 * description:
 */
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
public class BusinessException extends RuntimeException {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private Integer code;

    /**
     * 错误提示
     */
    private String message;

    public static BusinessException EXCEPTION(String message) {
        BusinessException common = new BusinessException();
        common.setCode(Result.FAIL);
        common.setMessage(message);
        return common;
    }

    public static BusinessException EXCEPTION(IResultCode resultCode) {
        BusinessException common = new BusinessException();
        common.setCode(resultCode.getCode());
        common.setMessage(resultCode.getMsg());
        return common;
    }
}
